package leetcode;

/**
 * @author Liangyaoyun
 */
public class leetCode45 {
    public int jump(int[] nums) {
        if (nums.length==1){
            return 0;
        }
        int end=0;
        int path=0;
        int count=0;
        int len= nums.length;
        for (int i = 0; i < len-1; i++) {
            path=Math.max(path,nums[i]+i);
            if (i == end) {
                end=path;
                count++;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        leetCode45 leetCode45 = new leetCode45();
        int[] nums = new int[]{1,3,2};
        int[] numsa = new int[]{2,3,1,1,4};
        System.out.println(leetCode45.jump(nums));
    }
}
